package cn.zcx;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * description:ReentrantLock
 * author:zcx
 * lenovo
 * 时间：2022.02.07.19.42
 */
public class T15 {
    Lock lock = new ReentrantLock();
    void m1(){
        lock.lock();
        for(int i=0; i<10; i++) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(i);
        }
        lock.unlock();
    }
    void m2(){
        lock.lock();
        System.out.println("m2()...");
        lock.unlock();
    }
    public static void main(String[] args) {

        var t = new T15();
        new Thread(t::m1,"t1").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(t::m2,"t2").start();
    }
}
